<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>

 <%
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
 %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
 		<link rel="stylesheet" type="text/css" href="<%=basePath %>/css/updateVideo.css" />
        <link rel="stylesheet" href="<%=basePath %>/css/list.css">
		<link href="<%=basePath %>/css/H-ui.min.css" rel="stylesheet" type="text/css" />
		<link href="<%=basePath %>/css/formsCSS.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>/css/simditor.css" />
		<script src="<%=basePath%>/lib/My97DatePicker/WdatePicker.js"></script>
		<script src="<%=basePath %>/js/jquery.min.js"></script>
		<script src="<%=basePath %>/js/formsJS.js"></script>
		
		<script type="text/javascript" src="<%=basePath %>/js/module.js"></script>
		<script type="text/javascript" src="<%=basePath %>/js/hotkeys.js"></script>
		<script type="text/javascript" src="<%=basePath %>/js/uploader.js"></script>
		<script type="text/javascript" src="<%=basePath %>/js/simditor.js"></script>
		<script type="text/javascript" src="<%=basePath %>js/H-ui.js"></script>
		<script src="<%=basePath %>/js/formsJS.js"></script>
		<script src="<%=basePath %>/js/jquery.form.js"></script>

<script type="text/javascript">

function checkForm(f){
	
			var loginUser = '${loginUser}'//当前登录用户
	
		 	if(f.userName.value.replace(/\s/g,'') == ''){
				alert("用户名称不能为空");
				return false;
			}
			
			if(f.nickName.value.replace(/\s/g,'') == ''){
				alert("用户昵称不能为空");
				return false;
			}
			if(f.password.value.replace(/\s/g,'') == ''){
				
				if('${type}'=='upd'){
					alert("请输入用户密码，如输入新密码与原密码不同，则默认保存新密码");
					return false;
				}else{
					alert("请输入密码");
					return false;
				}
			}
			if(f.telephone.value.replace(/\s/g,'') == ''){
				alert("用户手机不能为空");
				return false;
			}
			if(f.email.value.replace(/\s/g,'') == ''){
				alert("用户邮箱不能为空");
				return false;
			}
			
			//修改时，判断是否修改当前用户
			if('${type}'=='upd'){
		
				if(loginUser==f.userName.value){
					return true;
				}else{
					alert("只允许修改当前登录账户信息");
					return false;
				}
			}

 
	return true;
}
	function editUser(){
		 
		//获取角色
	 	var roleID =[]; 
		$('input[name="roles"]:checked').each(function(){ 
			 roleID.push($(this).val())
		});
		 
		//提交	
		$('#dataForm').submit(function() {
			$.ajax({
			   type: "POST",
			   async: false ,
			   data:{"roleID":roleID},
			   dataType:'json',
			   url: '<%=basePath%>/sysUserEdit',
			   success: function(data){
				 location.reload();
			   },
			});
		});
		 
	} 
	  

</script>
</head>
<body>
		<div class="connect_wrap">
    		<h3 style= "text-align: center;">系统用户信息维护</h3>
			<div class="row cl" style="max-width:88%;margin-left:8%;">
			<div class="labelText"></div>
				<form action="<%=basePath%>/sysUserEdit" method="post" onsubmit="return checkForm(this)" name="dataForm"
					enctype="multipart/form-data">
					<div class="col-sm-4"></div>
	    					<div class="col-sm-4">
	    							<div class="boxs">
												<input type="hidden" name="id" value="${sysUser.id}">
												<input type="text" class="inputBox" placeholder="用户名" name="userName" value="${sysUser.userName}" >
												<input type="text" class="inputBox" placeholder="用户密码" name="password" value="" >
												<input type="text" class="inputBox" placeholder="用户昵称" name="nickName" value="${sysUser.nickName}" >
												 
												<input type="text" class="inputBox" placeholder="用户手机" name="telephone" value="${sysUser.telephone}" >
												<input type="email" class="inputBox" placeholder="用户邮箱" name="email" value="${sysUser.email}" >
													
												 <select id="status" name="status" class="selectBox" placeholder="用户状态">
												  	<option value="">用户状态</option>
												  	<option value="1" ${sysUser.status == true ? 'selected="selected"' : '' }>启用</option>
										  			<option value="0" ${sysUser.status == false? 'selected="selected"' : '' }>禁用</option>
												</select>
												<br><br>
												
												<c:if test="${type eq 'add'}"> 
													<select class="selectBox" name="roleID" id="roleID" placeholder="用户角色">
									    				<option value="">用户角色</option>
										    			<c:forEach items="${roles}" var="r">
										    				<option value="${r.id}" ${r.id == userRole.roleID ? 'selected="selected"' : ''}>${r.id}:${r.intro}</option>
										    			</c:forEach>
						    						</select>  
					    						</c:if>
					    						
											  	<%-- 
											  	角色：<br/><br/>
												<div id="checkboxDiv">
												
												<table class="table table-border table-bordered table-striped table-hover">
										    		<tr >
										    			<td>选择</td>
										    			<td>角色名称</td>
										    			<td>角色说明</td>
										    		</tr>
										    		<c:if test="${not empty roles}">
										    			<c:forEach items="${roles}" var="role" varStatus="vs">
										    			<tr>
										    				<td><input type="checkbox" value="${role.id }" name="roles"></td>
											                <td>${role.name}</td>
											                <td>${role.intro}</td>
											    		</tr>
										    			</c:forEach>
										    		</c:if>
												</table> 
												
												</div> --%>
				 
												<br /><br />
												<!-- <input type="submit" value="确定" class="true"  onclick="editUser()"  /> -->
												<input type="submit" value="确定" class="true"   />
												<input type="button"  class="false" value="取消" onclick="window.history.go(-1)">
										</div>
								</div>
					</form>
			</div>
	</div>
	
</body>
<script type="text/javascript">
$(function(){
	if('${type}'=='upd'){
		$("input[name='userName']")	.attr("readonly","readonly");
		var loginUser = '${loginUser}'
	}
	
});

</script>
	 
</html>